package com.godtree.util.bazhuayu;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static com.godtree.util.bazhuayu.TokenTools.getToken;

/**
 * @author Lisicheng
 * @date 2020-6-4
 */
public final class TaskGroupTools {

  private static final String URL = "https://dataapi.bazhuayu.com/api/TaskGroup";

  /**
   * 获取任务组信息
   *
   * @return 任务id集合 List<String>
   */
  public static List<String> getTaskGroup() {
    JSONObject json =
        JSONObject.parseObject(
            HttpUtil.createGet(URL).header("Authorization", getToken()).execute().body());
    if (Constant.MSG.equals(json.getString(Constant.MSG_ERROR))) {
      return JSONUtil.parseArray(json.get("data")).stream().map(String::valueOf)
          .map(JSONObject::parseObject)
          .map(i -> i.getString("taskGroupId")).collect(Collectors.toList());
    }
    return Collections.emptyList();
  }
}
